package mainframe;

import javax.swing.ImageIcon;
import javax.swing.table.AbstractTableModel;


public class MemTableModel extends AbstractTableModel {
	private static final long serialVersionUID = 1L;
	String []title;
	Object content[][];
	Class<?>  columnType[];
	String []asmArray;
	int	asmLen;

	MemTableModel(){
		columnType = new Class[]{
				ImageIcon.class, ImageIcon.class, String.class, String.class, String.class
		};
		title = new String[]{
				"","", "Address", "Instruction", "Assemble"
		};
		this.initContent();
	}
	
	
	public void setAsmArray(String [] array, int len){
		asmArray = array;
		asmLen = len;
	}
	
	public void updateContent() {
		if (asmArray == null)
			return;
		for (int i=0; i<asmLen; i++) {
			content[i][3] = asmArray[i];
		}		
	}
	
	public void initContent() {
		content = new Object[1024][title.length];
		for (int i=0; i<1024; i++) {
			content[i][0] = new ImageIcon("");
			content[i][1] = new ImageIcon("");
			content[i][2] = new String("0x" + Integer.toHexString(i).toUpperCase());
			content[i][3] = new String("");
			content[i][4] = new String("");
		}
	}
	

	@Override
	public int getColumnCount() {
		// TODO Auto-generated method stub
		if (title != null)
			return this.title.length;
		return 0;
		}

	@Override
	public int getRowCount() {
		// TODO Auto-generated method stub
		return this.content.length;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		// TODO Auto-generated method stub
		return content[rowIndex][columnIndex];

	}
	
	public Class<?> getColumnClass(int col) {
		return columnType[col];
	}
	
    public	String	getColumnName(int col){
        return 	title[col];
    }

}
